var oUser = document.querySelector('#inputuser')
var oPass = document.querySelector('#inputpass')
let oLogin = document.querySelector('#btn')
console.log(oUser,oPass,oLogin);
// 节流
var flag = true

function fn() {
    if (flag) { 
        pAjax({
            url: '../server/login.php',
            type: 'post',
            data: {
                username: oUser.value,
                password: oPass.value
            }
        }).then(function (res) {
            // 此时是字符串，要变成对象
            
            let json = JSON.parse(res)
            
            if (json.err === 0) {
                alert(json.msg)
                // 登陆成功
                // 存一个localStorage
                localStorage.setItem('token', '8923jsdsdk9sdhosj92ol2')
                localStorage.setItem('username', oUser.value)

                // 跳转到index
                location.href = 'me.html'
            } else {
                alert(json.msg)
                // 打开节流
                flag = true
            }
        })
    }
    flag = false
}

oPass.addEventListener('keydown', function (ev) {
    if (ev.keyCode === 13) {
        fn()
    }
})

oLogin.addEventListener('click', fn)

// localStorage.setItem('user', )
